<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px
        }
    </style>
</head>

<body style="color:#333;padding:3px;font-size:12px" class="x_sorll">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">常规促销申请明细</h2>
</div>
<!-- 标题 -->
<div>
    <table class="table-bordered table">
        <tr>
            <td><a href="{:url('formalbacklogdetail',['trackId'=>request()->param('trackId'),'workId'=>request()->param('workId'),'myId'=>request()->param('myId')])}" class="btn btn-sm btn-primary">审批决策宝</a></td>
        </tr>
    </table>
    <form action="" class="form-inline" id="form2">
        <table class="table row-margin-top table-bordered bud_hei">
            <tr>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">编号</label></td>
                <td>{$ti.sn}</td>
                <td style="min-width: 120px;width: 120px"><label for="" class="form-label">创建时间</label></td>
                <td>{:date("Y-m-d H:i",$ti.ctime)}</td>
            </tr>
            <tr>
                <td><label for="" class="form-label">申请人</label></td>
                <td><a href="javascript:;">{$ti.cuser_name}({$ti.cuser_job})</a></td>
                <td><label for="" class="form-label">部门</label></td>
                <td>{$ti.cuser_de}</td>
            </tr>
            <tr>
                <td><label for="" class="form-label">状态</label></td>
                <td>{$ti.state}</td>
                <td><label for="" class="form-label">审批时间</label></td>
                <td>{:date('Y-m-d H:i')}</td>
            </tr>
            <tr>
                <td><label for="" class="form-label">主题</label></td>
                <td colspan="3">{$ti.title}</td>
            </tr>
            <tr>
                <td><label for="" class="form-label">经销商名称</label></td>
                <td colspan="3"<span class="font-bold">{$ti.jxs_name} <a href="{:url('Commonti/jxsyj')}?aid={$ti.id}" class="J_menuItem"><span style="display: none;">经销商决策信息</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true"></span></a></span></td>
            </tr>
            <tr>
                <td><label for="" class="form-label">经销商基本信息</label></td>
                <td colspan="3">所属分区：<span>{$ti.zoning}</span> 所属省份：<span>{$ti.provice}</span>
                    所属城市：<span>{$ti.city}</span> 性质：<span>{if $ti.direct==1}直营{else}非直营{/if}</span></td>
            </tr>
        </table>
        <table class="table table-striped table-bordered text-center bud_hei" style="margin-top: 1px;">
            <thead>
            <tr class="info">
                <th class="text-center" rowspan="2">审批人</th>
                <th class="text-center" rowspan="2">序号</th>
                <th class="text-center" rowspan="2">明细编号</th>
                <th class="text-center" rowspan="2">系统名称</th>
                <th class="text-center" rowspan="2">负责人</th>
                <th class="text-center" rowspan="2">网点名称</th>
                <th class="text-center" rowspan="2">产品系列</th>
                <th class="text-center" rowspan="2">促销产品</th>
                <th class="text-center" rowspan="2">促销执行时间</th>
                <th class="text-center" rowspan="2">预计核销时间</th>
                <th class="text-center" colspan="2">预计销售量</th>
                <th class="text-center" rowspan="2">需补差销售量</th>
                <th class="text-center" rowspan="2">标准<br>出厂价</th>
                <th class="text-center" rowspan="2">经销商<br>原供货价</th>
                <th class="text-center" rowspan="2">经销商<br>现供货价</th>
                <th class="text-center" rowspan="2">经销商<br>折价率</th>
                <th class="text-center" rowspan="2">经销商总<br>折价金额</th>
                <th class="text-center" rowspan="2">经销商<br>毛利率</th>
                <th class="text-center" rowspan="2">网点<br>正常供货价</th>
                <th class="text-center" rowspan="2">网点<br>促销供货价</th>
                <th class="text-center" rowspan="2">网点<br>折价率</th>
                <th class="text-center" rowspan="2">网点<br>折价金额</th>
                <th class="text-center" rowspan="2">原零售价</th>
                <th class="text-center" rowspan="2">活动期零售价</th>
                <th class="text-center" rowspan="2">网点<br>毛利率</th>
                <th class="text-center" rowspan="2">费用名称</th>
                <th class="text-center" rowspan="2">未税费用金额(元)</th>
                <th class="text-center" rowspan="2">是否增值税(可抵扣)</th>
                <th class="text-center" rowspan="2">税率</th>
                <th class="text-center" rowspan="2">含税费用金额(元)</th>
                <th class="text-center" rowspan="2">实际投入费用(元)</th>
                <th class="text-center" rowspan="2">费用描述</th>
                <th class="text-center" rowspan="2">费用支付方式</th>
                <th class="text-center" rowspan="2">费用小计(元)</th>
                <th class="text-center" rowspan="2">预计<br>费用率</th>
                <th class="text-center" rowspan="2">基准销量</th>
                <th class="text-center" rowspan="2">预计<br>ROI</th>
                <th class="text-center" rowspan="2">备注</th>
                <th class="text-center" rowspan="2">操作</th>
                <th class="text-center" rowspan="2">是否要求<br>核查</th>
                <th class="text-center" rowspan="2">费用计入部门</th>
                <th class="text-center" rowspan="2">计入部门修改人</th>
                <th class="text-center" rowspan="2">费用计入方案</th>
                <th class="text-center" rowspan="2">计入方案修改人</th>
            </tr>
            <tr class="info">
                <th class="text-center">单品</th>
                <th class="text-center">销售额</th>
            </tr>
            </thead>
            {volist name="ti_list" id="row" key="k"}
            <tr  profit='{$row.profit}' class="text-left text-success" >
                <input type="hidden" name="list_id[]" value="{$row.did}">
                <td></td>
                <td>{$k}<span class="colorRed duigou" title="此单申请时间在活动开始时间之后">补单</span></td>
                <td><a href="{:url('TiApply/dataview')}?did={$row.did}" class="J_menuItem" title="{$row.no}"> {$row.no}_{$row.detail_no}</a><a href="{:url('Commonti/decisionb')}?did={$row.did}"  class="J_menuItem"><span style="display: none;">决策信息</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a>
                
                <td>{$row.xitong}</td>
                <td>{$row.fuzeren}</td>
                <td>{$row.net}<a href="{:url('Commonti/netyj')}?did={$row.did}" class="J_menuItem"><span style="display: none;">网点决策依据</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
                <td>{$row.series_name}<a href="{:url('Commonti/seriosroi')}?did={$row.did}" class="J_menuItem"><span style="display: none;">ROI决策信息</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
                <td><span class="glyphicon glyphicon-warning-sign jinchang" aria-hidden="true"
                          title="此条码在申请时未进场"></span>{$row.pro_name}<a href="{:url('Commonti/productroi')}?did={$row.did}" class="J_menuItem"><span style="display: none;">ROI决策信息</span><span class="glyphicon glyphicon-zoom-in fangda" aria-hidden="true" style="display: inline-block;"></span></a></td>
                <td>{$row.start_time}<br>{$row.end_time}</td>
                <td>{$row.hexiao_time}</td>
                <td><span class="num2">{$row.sell_num}</span>箱</td>
                <td class="text-right num2">{$row.xiaoshoue}</td>
                <td class="text-right num2">{$row.bucha}</td>
                <td class="text-right"><span class="num2">{$row.factory}</span>元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.yuan_price}</span>元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.now_price}</span>元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.zhejia}</span>% OFF</td>
                <td class="ObjectNum text-right num2">{$row.jxscha}</td>
                <td class="text-right"><span class="num2">{$row.maoli}</span>%</td>
                <td class="text-right"><span class="num2">{$row.wangdian_yuan}</span>元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.wangdian_price}</span>元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.wangdian_zhejia}</span>% OFF</td>
                <td class="ObjectNum text-right num2">{$row.netcha}</td>
                <td class="text-right">{$row.lingshou_price}元/{$row.unit}</td>
                <td class="text-right">{$row.huodong_price}元/{$row.unit}</td>
                <td class="text-right"><span class="num2">{$row.wangdianmaoli}</span>%</td>
                <td>{$row.feiyong3}</td>
                <td><span class="yws">{$row.zonge}</span>/<input type="text" style="width: 80px;" name="pzwsfyje[]" value="{$row.pizhunweishui}"
                                  onblur="editorInput(this)" class="zhiDuInput form-control listMoney1" readonly="">
                    <img id="weiShuiEditImg1" width="20px" height="20px"
                         style="cursor: pointer; display: inline;vertical-align: bottom;" title="修改"
                         src="__STATIC__/layout/img/xiugai.png" onclick="editWeiShui(this);">
                    <img id="weiShuiQueRenImg1" width="30px" height="20px" onclick="saveWeiShui(this);"
                         style="cursor: pointer; display:none ;vertical-align: bottom;" title="保存"
                         src="__STATIC__/layout/img/baocun.png">
                    <!--     <img id="jiaZaiImg1" width="20px" height="20px" style="display: none;" src="/xiaolutong/web/images/process/072.gif"> -->
                    <br>
                    <span id="editWeiShuiMsg1" style="color: red; display: none;"></span>

                    <span class="editWeiShuiMsgOK1" style="color: green; display: none;">修改成功！</span>
                    <span class="editWeiShuiMsgNO1" style="color: red; display: none;">修改成功！</span>
                </td>
                <td>{if $row.dikou==1}是{else/}否{/if}</td>
                <td class="num2">{$row.shuilv}</td>
                <td class="num2">{$row.hanshui}</td>
                <td class="text-right ObjectNum num2">{$row.hanshui}</td>
                <td class="text-right">{$row.remark}</td>
                <td>
                    <select name="fyzffs[]"  class="form-control select" style="color:#333">
                        <option value="">请选择</option>
                        {volist name='fyzffs' id='fs'}
                        <option value="{$fs.id}" {if trim($fs.title)==trim($row.zffs)}selected{/if}>{$fs.title}</option>
                        {/volist}
                    </select>
                </td>
                <td class="text-right ObjectNum num2">{$row.hanshui}</td>
                <td class="text-right "><span class="num2">{$row.yujifeiyonglv}</span>%</td>
                <td class="text-right ObjectNum" jz="{$row.totalBenchmarkSales}">{$row.jizhunboxnum}</td>
                <td class="text-right"><span class="num2">{$row.yujiroi}</span>%</td>
                <td>{$row.beizhu}</td>
                <td class="text-left">
                    <div class="form-group">
                        <select class="isorno" zonge="{$row.zonge}">
                            <option value="1">同意</option>
                            <option value="0" {if $row.isOrNo===0}selected {/if}>否决</option>
                        </select>
                        <!--<label class="radio-inline" >
                            <input type="radio" name="isOrNo[]" value="agree">同意
                        </label>
                        <label class="radio-inline" >
                            <input type="radio" checked name="isOrNo[]" value="noPass">否决
                        </label>-->
                    </div>
                    <br>
                    <span class="editCaozuoOK1" style="color: green; display: none;">修改成功！</span>
                    <span class="editCaozuoNo1" style="color: red; display: none;"></span>
                </td>
                <td class="text-center">
                    <select name="sfyqhc[]" >
                        <option value="0">否</option>
                        <option value="1" {if $row.sfyqhc==1} selected {/if}>是</option>
                    </select>
                </td>
                <td>
                    <select name="fyjrbm[]"  class="form-control select" style="color:#333">
                        
                        {volist name="fyjrbm" id="bm"}
                        <option value="{$bm.id}" {if $bm.title==$row.de_name}selected{/if}>{$bm.title}</option>
                        {/volist}
                    </select>
                </td>
                <td></td>
                <td>
                    <select name="jrfa[]" class="form-control select" style="color:#333">
                        
                        {volist name="fyjrfa" id="fa"}
                        <option value="{$fa.id}" {if $row.jrfa==$fa.title}selected{/if}>{$fa.title}</option>
                        {/volist}
                    </select>
                </td>
                <td></td>
            </tr>
            {/volist}
        </table>
        <table class="table table-bordered" style="margin:0;padding: 0">
            <tr>
                <td class="font-bold">本申请中包含<span>{$wds}</span>个网点，其中<span id="feelie">{volist name="sjfykm" id="v"}{$v.feetype_name}：<span class="num2">{$v.sqje}</span>元；{/volist}</span>总费用：<span
                        class="num2 zongfeiyong">{$zfy}</span>元。总预计销售额：<span class="ObjectNum num2">{$zyjxl}</span>元；总费用率：<span
                        class="num2" id="zfyl">{$zfyl}</span>%；总ROI: <span class="zongroi num2">{$zongroi}</span>%；<a href="javascript:;"
                                                                                                     class="btn btn-sm btn-primary"
                                                                                                     id="yasuofeiyong">压缩费用</a>
                </td>
            </tr>
        </table>
        <table class="table table-bordered text-left bud_hei">
            <tr class="info">
                <th class="text-left font-bold">审批意见</th>
            </tr>
            {volist name="logs" id="l"}
          <tr>
              <td>{$l.USERNAME} 审批动作：{$l.MEMO}；审批意见：{if $l.COMMENTS}{$l.COMMENTS}{else/}无{/if}(审批时间：{$l.ACTIONTIME})</td>
          </tr>
          
          {/volist}
      </table>
        <table class="table-bordered table row-margin-top">
            <tr>
                <td colspan="2">
                    <label for="isfunkui"><input type="checkbox" class="" name="sfxyfk" {if $ti.sfxyfk==1} checked {/if} id="isfunkui" value="1">是否需要反馈</label>
                    <span class="colorRed">(如需反馈请勾选)</span>
                </td>
            </tr>
        </table>
    <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0">
        <input type="submit" class="btn btn-success" value="进入下一步" id="tijiao">
    </div>
</form>

<!-- 压缩费用 start-->
<div id="yasuo" style="display: none;" class="ibox ibox-content">
    <h1 class="title_color">
        常规促销申请压缩费用
    </h1>
    <form action="" id="form1">
            <input type="hidden" name="ti_id" value="{:request()->param('id')}"> 
        <table class="table row-margin-top table-bordered text-center bud_hei">
            <tr class="info">
                <th>费用科目</th>
                <th>网点数</th>
                <th>产品数</th>
                <th>申请金额(元)</th>
                <th>核准金额(元)</th>
            </tr>
            {volist name="sjfykm" id="row"}
            <tr class="fee">
                <td>{$row.feetype_name}<input type="hidden" name="feetype[]" value="{$row.feetype}"></td>
                <td>{$row.jxss}</td>
                <td>{$row.pps}</td>
                <td class="fmaxj" fid='{$row.feetype}'>{$row.sqje}</td>
                <td><input type="text" name="hzje[]" class="form-control ysje"></td>
            </tr>
            {/volist}
            <!--   {/volist} -->
            <tr>
                <td colspan="5">
                    备注：上述核准金额为：被允许的最大实际投入金额。不包含否决项。 实际投入金额为实际扣除预算的金额。当客户提供的发票为普通发票或增值税普通发票（不可抵扣）时，
                    则实际投入金额为发票含税（价税合计）金额。当客户提供的发票为增值税专用发票（可抵扣）时， 则实际投入金额为发票未税（不含税）金额。
                </td>
            </tr>
        </table>
        <div class="row">
            <div class="text-center padding-10 trTotal">核准金额合计：<span class="colorRed font-bold" id="hzjehj">2222.60</span> 元</div>
        </div>
    </form>
</div>
<!-- 压缩费用 end-->

</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/common.js"></script>
  <script src="__STATIC__/layout/js/contabs_sub.js"></script>
<script>
$(".ysje").blur(function(){
    if(isNaN(parseFloat($(this).val()))){
        $(this).val("0.00");
    }
    else{
        $(this).val(parseFloat($(this).val()).toFixed(2));
    }
})
//压缩费用
    $("#yasuofeiyong").click(function () {
          $.ajax({ 
            type: "post", 
            url: "{:url('getformat')}", 
            cache:false, 
            async:false, 
            data:{aid:{$ti.id}}, 
            success: function(re){ 
              var datas=JSON.parse(re);
              var data=datas[0];
              $(".ysje").val('');
              $(".ysje").prop("readonly",false)
              $(".fmaxj").each(function(){
                for(var i=0;i<data.length;i++){
                    if($(this).attr("fid")==data[i]["feetype"]){
                        if(parseFloat(data[i]["maxje"])==0){
                            $(this).next().children().val(0).prop("readonly",true);

                        }
                        $(this).html(parseFloat(data[i]["maxje"]).toFixed(2))
                        break;
                    }
                }
              })
              $("#hzjehj").html(parseFloat(datas[1]).toFixed(2))
              
              layer.open({
                    type: 1,
                    title: '压缩费用',
                    area: ['700px', '500px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: $('#yasuo'),
                    btn: ['确定', '返回'],
                    yes: function (i, o) {
                        var param = $('#form1').serialize()
                        $.post('{:url("ysfy_cg")}', param, function (vo) {
                            var vos=JSON.parse(vo)
                            if(vos["state"]==1){
                                swal({title: '操作已成功'}, function () {
                                    layer.close(i)
                                    location.reload()
                                })
                            }else{
                                swal({title:vos["msg"]})
                            }
                        })
                    }
                });
            } 

        });
        /*layer.open({
            type: 1,
            title: '压缩费用',
            area: ['700px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: $('#yasuo'),
            btn: ['确定', '返回'],
            yes: function (i, o) {
                var param = $('#form1').serialize()
                $.post('{:url("ysfy_cg")}', param, function (data) {
                    if (data.success) {
                        swal({title: data.msg}, function () {
                            layer.close(i)
                            location.reload()
                        })
                    } else {
                        swal(data.msg)
                    }
                }, 'json')
            }
        });*/
    })
function hedui(){
    $.post("{:url('feihedui')}",{aid:{$ti.id}},function(re){
        var data=JSON.parse(re);
        var kemu=data[0];
        $("#feelie").html("");
        for(var i=0;i<kemu.length;i++){
            $("#feelie").append(kemu[i]["feetype_name"]+"：<span>"+parseFloat(kemu[i]["sqje"]).toFixed(2)+"</span>元；")
        }
        $(".zongfeiyong").html(parseFloat(data[1]).toFixed(2))
        $("#zfyl").html(parseFloat(data[2]).toFixed(2))

        $(".zongroi").html(parseFloat(data[3]).toFixed(2))
        
    })
}
$(".isorno").change(function(){
   //if($(this))
   var did=$(this).parent().closest('tr').children().eq(0).val();
   if($(this).val()==1){
        var weishui=parseFloat($(this).attr("zonge")).toFixed(2);
   }else{
        var weishui=0;
   }
    var shuilv=$(this).parent().closest('tr').find('td:nth-child(31)').html();
    var hanshui=parseFloat(weishui)+parseFloat(weishui)*parseFloat(shuilv)/100
    var jizhunxiaoliang= $(this).parent().closest('tr').find('td:nth-child(38)').attr("jz");
    var sjtrfy = hanshui
    var fyxj = sjtrfy
    var yjxl = $(this).parent().closest('tr').find('td:nth-child(13)').html()
    var yjfyl = (fyxj/parseFloat(yjxl)*100).toFixed(2)
    var profit=parseFloat($(this).parent().closest('tr').attr("profit"))/100;
    //alert(did);
    if(hanshui!=0)
        var yjroi=(yjxl-jizhunxiaoliang)*profit/hanshui;
    else
        var yjroi=0;
    yjroi=yjroi.toFixed(2)
    var t=$(this)
    $.ajax({ 
            type: "post", 
            url: "{:url('formmatsave')}", 
            cache:false, 
            async:false, 
            data:{did:did,pizhunweishui:parseFloat(weishui).toFixed(2),pizhunhanshui:hanshui.toFixed(2),yjfyl:yjfyl,yjroi:yjroi,isorno:t.val()}, 
            success: function(re){ 
               // alert(re);
                var da=JSON.parse(re);
                if(da["state"]==1){
                    t.parent().closest('tr').find('td:nth-child(32)').html(hanshui.toFixed(2))
                    t.parent().closest('tr').find('td:nth-child(33)').html(hanshui.toFixed(2))
                    t.parent().closest('tr').find('td:nth-child(36)').html(hanshui.toFixed(2))
                    t.parent().closest('tr').find('td:nth-child(37)').html(yjfyl+'%')
                    t.parent().closest('tr').find('td:nth-child(39)').html(yjroi+"%")
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(3).css("display", "none");
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(2).css("display", 'inline');
                    t.parent().next().next().next().css("display", 'none');
                    t.parent().next().next().css("display", 'block');
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(1).val(parseFloat(weishui).toFixed(2));
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(1).attr("readonly", "readonly");
                    hedui();
                }else{
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(3).css("display", "none");
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(2).css("display", 'inline');
                    t.parent().next().next().next().css("display", 'block');
                    t.parent().next().next().next().html(da["msg"]);
                    t.parent().next().next().css("display", 'none');
                    t.parent().closest('tr').find('td:nth-child(29)').children().eq(1).attr("readonly", "readonly");
                    if(t.val()==1)
                        t.val(0)
                    else
                        t.val(1)
                }
            } 

        });
})
    $(document).ready(function () {
        $(".num2").each(function(){
            if(isNaN(parseFloat($(this).html())))
                $(this).html("0.00");
            else    
                $(this).html(parseFloat($(this).html()).toFixed(2))
        })
        var $ObjectNum = $(".ObjectNum");
        toNum($ObjectNum);

        //提交工作流
        $('#tijiao').click(function () {
            var param = $('#form2').serialize()
            $.post('{:url("tjsp_cg2")}',param,function (data) {
                var re=JSON.parse(data);
                if(re['state']==1){
                    swal({title:"保存成功"},function () {
                        location.href='{:url("gzlsp",["workId"=>request()->param("workId"),"trackId"=>request()->param("trackId")])}'
                        return false
                    })
                }else{
                    swal({title:re["msg"]})
                }
            })
            return false
        })

        //输入核准金额
        $("[name='hzje[]']").on('input',function () {
            var hj = 0;
            $("[name='hzje[]']").each(function (i,o) {
                var v = $(o).val()
                hj += parseFloat(v);
            })
            $('#hzjehj').html(hj)
        })
    });

    function back() {
        history.go(-1)
    }

    //编辑未税
    function editWeiShui(which) {
        var $td = $(which).closest('td')
        var isorno=$td.closest('tr').find('td:nth-child(41)').children().eq(0).children().eq(0).val();
        //alert(isorno)
        // console.log($(this))
        if(isorno==1){
            $(which).css("display", "none");
            $(which).siblings('img').css("display", 'inline');
            $(which).siblings(".editWeiShuiMsgOK1").css("display", 'none');
            $(which).siblings(".listMoney1").removeAttr("readonly");
        }else{
            alert('否决状态下不能修改金额')
        }
        
    };

    //保存未税
    function saveWeiShui(which) {
        var $td = $(which).closest('td')
        var yws = $td.find("[name='pzwsfyje[]']").val()
        var shuilv = $td.next().next().html()
        var jizhunxiaoliang= $td.next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').attr('jz')
       // alert(shuilv);
        var hanshui =parseFloat(yws)+ parseFloat(yws)*parseFloat(shuilv)/100
        var sjtrfy = hanshui
        var fyxj = sjtrfy
        var yjxl = $td.closest('tr').find('td:nth-child(13)').html()
        //alert(yjxl);
        var yjfyl = (fyxj/parseFloat(yjxl)*100).toFixed(2)
        var profit=parseFloat($td.parent().attr("profit"))/100;
        //alert(hanshui);
        if(hanshui!=0)
            var yjroi=(yjxl-jizhunxiaoliang)*profit/hanshui;
        else
            var yjroi=0;
        //alert(yjxl);
        yjroi=yjroi.toFixed(2)
        $.ajax({ 
            type: "post", 
            url: "{:url('formmatsave')}", 
            cache:false, 
            async:false, 
            data:{did:$td.parent().children().eq(0).val(),pizhunweishui:parseFloat(yws).toFixed(2),pizhunhanshui:hanshui.toFixed(2),yjfyl:yjfyl,yjroi:yjroi}, 
            success: function(re){ 
                var da=JSON.parse(re);
                if(da["state"]==1){
                    $td.next('td').next('td').next('td').html(hanshui.toFixed(2))
                    $td.next('td').next('td').next('td').next('td').html(sjtrfy.toFixed(2))
                    $td.next('td').next('td').next('td').next('td').next('td').next('td').next('td').html(fyxj.toFixed(2))
                    $td.next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').html(yjfyl+'%')
                    $td.next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').html(yjroi+"%")
                    $(which).css("display", "none");
                    $(which).siblings('img').css("display", 'inline');
                    $(which).siblings(".editWeiShuiMsgNo1").css("display", 'none');
                    $(which).siblings(".editWeiShuiMsgOK1").css("display", 'block');
                    $(which).siblings(".listMoney1").attr("readonly", "readonly");hedui();
                }else{
                    $(which).css("display", "none");
                    $(which).siblings('img').css("display", 'inline');
                    $(which).siblings(".editWeiShuiMsgNo1").css("display", 'block');
                    $(which).siblings(".editWeiShuiMsgNo1").html(da["msg"]);
                    $(which).siblings(".editWeiShuiMsgOK1").css("display", 'none');
                    $(which).siblings(".listMoney1").attr("readonly", "readonly");
                }
            } 

        });
        
    }

    function editorInput(which) {
        $(which).attr("readonly", "readonly");
    }

    
    $(".pronum").click(function () {
        var str = '<div id="pronum" class="ibox-content">' +
            '<h2 class="title_color text-center">产品列表</h2>' +
            '<form action="#" id="form0">' +
            '<table class="table table-bordered">' +
            '<tr>' +
            '<td>No.</td>' +
            '<td>产品编号</td>' +
            '<td>产品名称</td>' +
            '</tr>' +
            '<tr>' +
            '<td>1</td>' +
            '<td>1021232</td>' +
            '<td>07肇庆裹蒸棕</td>' +
            '</tr>' +
            ' <tr>' +
            '<td>2</td>' +
            '<td>1021232</td>' +
            '<td>07肇庆裹蒸棕</td>' +
            '</tr>' +
            '</table>' +
            '</form>' +
            '</div>'
        layer.open({
            type: 1,
            title: '产品明细列表',
            area: ['500px', '400px'],
            fixed: false, //不固定
            maxmin: true,
            content: str,
        });
        return false;
    })
    $(".netnum").click(function () {
        var str = '<div id="pronum" class="ibox-content">' +
            '<h2 class="title_color text-center">网点列表</h2>' +
            '<form action="#" id="form0">' +
            '<table class="table table-bordered">' +
            '<tr>' +
            '<td>No.</td>' +
            '<td>网点编号</td>' +
            '<td>网点名称</td>' +
            '</tr>' +
            '<tr>' +
            '<td>1</td>' +
            '<td>1021232</td>' +
            '<td>万家天河东分店</td>' +
            '</tr>' +
            ' <tr>' +
            '<td>2</td>' +
            '<td>1021232</td>' +
            '<td>高德吉之岛分店</td>' +
            '</tr>' +
            '</table>' +
            '</form>' +
            '</div>'
        layer.open({
            type: 1,
            title: '网点明细列表',
            area: ['500px', '400px'],
            fixed: false, //不固定
            maxmin: true,
            content: str,
        });
        return false;
    })


    /*请输入关键字或空格查询*/
    var jieshou = $("#area_id");
    sousuo(jieshou);

    function sousuo(id) {
        id.bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: true, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: 'http://unionsug.baidu.com/su?p=3&t=' + (new Date()).getTime() + '&wd=',
            /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            jsonp: 'cb',
            /*如果从 url 获取数据，并且需要跨域，则该参数必须设置*/
            processData: function (json) { // url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {
                    value: []
                };
                if (!json || !json.s || json.s.length === 0) {
                    return false;
                }

                // console.log(json);
                len = json.s.length;

                jsonStr = "{'value':[";
                for (i = 0; i < len; i++) {
                    data.value.push({
                        word: json.s[i]
                    });
                }
                data.defaults = 'baidu';

                //字符串转化为 js 对象
                return data;
            }
        });

    }


    $("#addShenpiMan").click(function () {
        var str = '<tr><td><div class="input-group"><input id="area_id" type="text" placeholder="请输入关键字或空格查询" class="form-control" value="" style="min-width: 300px;width: 300px"><div class="input-group-btn"><ul class="dropdown-menu dropdown-menu-right" role="menu"></ul></div></div></div></td><td> <a href="javascript:;" id="select_area" class="btn btn-primary btn-sm">选择</a><span></span> <button class="btn btn-sm btn-danger delthis" type="button">删除</button></td></tr>'
        $("#flowTab tbody").append(str);
    })

    $(document).on("click", ".delthis", function () {
        var _$this = this
        console.log(_$this)
        swal({
                title: "",
                text: "确定删除！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function (isConfirm) {
                if (isConfirm) {
                    // console.log(_$this);
                    $(_$this).closest("tr").remove();
                    swal("删除！", "成功", "success");

                } else {
                    swal("取消！", "", "error");
                }
            });
    });

</script>
</body>

</html>
